package com.legendshop.oa.model;

import java.io.Serializable;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import com.legendshop.framework.model.GrantedFunction;

public class AdminUserDetail extends User implements Serializable {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -5898134878028341628L;

	/** The functions. */
	private final Collection<GrantedFunction> functions;

	/** The user id. */
	private final String userId;

	/** 登录类型 **/
	private final String logType;

	/** 部门Id */
	private Integer deptId;
	

	private  String ipAddress;
	
	public AdminUserDetail(String username, String password, Collection<? extends GrantedAuthority> authorities,
			Collection<GrantedFunction> functions, String userId, String logType,  Integer deptId) {
		super(username, password, authorities);
		this.functions = functions;
		this.userId = userId;
		this.logType = logType;
		this.deptId = deptId;
	}



	public Integer getDeptId() {
		return deptId;
	}

	public void setDeptId(Integer deptId) {
		this.deptId = deptId;
	}

	public Collection<GrantedFunction> getFunctions() {
		return functions;
	}

	public String getUserId() {
		return userId;
	}

	public String getLogType() {
		return logType;
	}

	/**
	 * 在做并发控制时, 以userId来区分一个唯一的用户.
	 */
	public boolean equals(Object object) {
		if (object instanceof AdminUserDetail) {
			if (this.userId.equals(((AdminUserDetail) object).getUserId()))
				return true;
		}
		return false;
	}

	public int hashCode() {
		return this.userId.hashCode();
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}
	
	

}
